//-----------------Sonic CD Push Button Script----------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.PropertyValue	:	Object.Pressed

// Gravity
#alias 0	:	GRAVITY_GROUND

// Stage SFX
#alias 8	:	SFX_S_SWITCH

// HUD Alias
#alias Object[24].PropertyValue	:	HUD.CurrentTimePeriod


sub ObjectPlayerInteraction
	if Object.Pressed == false
		if Player.YVelocity >= 0
			PlayerObjectCollision(C_BOX, -16, -8, 16, 8)
			if CheckResult == true
				Object.Pressed = true
				Player.YPos   += 0x80000
				PlayStageSfx(SFX_S_SWITCH, false)
			else
				Object.Pressed = false
			end if
		else
			Object.Pressed = false
		end if
	else
		PlayerObjectCollision(C_TOUCH, -16, -2, 16, 8)
		if CheckResult == true
			if Player.YVelocity > -1
				Object.Pressed   = true
				Player.Gravity   = GRAVITY_GROUND
				Player.YVelocity = 0

				Player.YPos   = Player.CollisionBottom
				FlipSign(Player.YPos)
				Player.YPos <<= 16
				Player.YPos  += Object.YPos
			end if
		else
			Object.Pressed = false
			if Player.YVelocity > -1
				Player.Gravity   = GRAVITY_GROUND
				Player.YVelocity = 0

				Player.YPos   = Player.CollisionBottom
				FlipSign(Player.YPos)
				Player.YPos  -= 8
				Player.YPos <<= 16
				Player.YPos  += Object.YPos
			end if
		end if
	end if
end sub


sub ObjectDraw
	DrawSprite(Object.Pressed)
end sub


sub ObjectStartup
	LoadSpriteSheet("R4.5/Objects.gif")

	SpriteFrame(-16, -8, 32, 16, 224, 157)	// #0 - Push Button
	SpriteFrame(-16, -8, 32, 16, 224, 174)	// #1 - Push Button pressed
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("R4/Objects.gif")

	SpriteFrame(-16, -8, 32, 16, 130, 35)	// #0 - Push Button

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub
